package adapter.main.power;

import adapter.main.power.v12.IPower12;

/**
 * 电源适配器（实现目标对象接口，即12V电源接口）,类适配器模式
 */
public class AdapterPower12Ext extends AbsBasePower implements IPower12 {
    //已经存在的电源
    public AdapterPower12Ext(AbsBasePower absBasePower) {
        super(absBasePower.getPower());
    }

    //实现目标对象发放
    @Override
    public void output12v() {
        //获得外部电源值
        float powerFloat = this.getPower();
        //进行电源转换
        if (powerFloat == 380) {
            //380V电源转换
            powerFloat = powerFloat / 21.67f;
        } else if (powerFloat == 220) {
            powerFloat = powerFloat / 18.33f;
        } else if (powerFloat == 110) {
            powerFloat = powerFloat / 9.17f;
        } else {
            System.out.println("没有找到适配电源");
            return;
        }

        powerFloat = (int) (powerFloat * 10) / 10.0f;
        //处理转换结果
        System.out.println(String.format("这是%.1f%s的电源", powerFloat, this.getUnit()));
    }
}
